// https://github.com/microsoft/TypeScript/issues/43020#issuecomment-790994531
{
  type FirstNL<T extends any[]> = T extends [infer F, ...infer R] ? [F] : never;
  type First<T extends unknown[]> = T extends []
    ? []
    : T extends [unknown, ...infer R]
      ? T extends [...infer F extends [unknown], ...R]
        ? F
        : never
      : T extends [unknown?, ...infer R2]
        ? T extends [...infer F2, ...R2]
          ? [unknown?] extends F2
            ? 'here'
            : F2
          : never
        : never;

  type Test = First<[a: number, b: boolean, c: string]>;
  //    ^?
  // type Test = [a: number]

  type Test2 = First<[a: number, b: boolean, c: string]>;
  //    ^?

  type X = First<[a?: number, b?: boolean, c?: string]>; // never
  //   ^?
  type Y = First<[...a: number[], b: boolean, c: string]>; // never
  //   ^?
  type Z = First<[a: number, ...b: boolean[], c: string]>; // unknown[]
  //   ^?
  type A = First<[number]>;
  //   ^?
}

{
  type SomeTuple = [callback: (x: number, y: boolean) => void];

  type InferNestedArgs<T> = T extends [(...cbArgs: infer CbArgs) => void]
    ? CbArgs
    : never;

  type Path1 = [...[added: Error], ...InferNestedArgs<SomeTuple>];

  type BrokenTpl<T> = [...[newErr: Error], ...InferNestedArgs<T>];
  type Path2 = BrokenTpl<SomeTuple>;

  type MakeError<T extends never> = T;
  // let a: MakeError<Path1> // yields [added: Error, x: number, y: boolean]
  // let b: MakeError<Path2> // yields [Error, number, boolean]
}
{
  type FirstAsTuple<T extends any[]> = T extends []
    ? never
    : T extends [any?, ...infer TAIL]
      ? T extends [...infer HEAD, ...TAIL]
        ? HEAD
        : never
      : never;
  type test = FirstAsTuple<[a?: number, b?: number]>;
  //       ^?
}

{
  type _A = ArrayConstructor extends {
    prototype: infer T;
  }
    ? T
    : never;

  type _V = (<T extends 1 | boolean>(args: T) => void) extends (inf: infer T | 1) => void
    ? T
    : never;
}
